//
//  CommentCell.m
//  QSBK
//
//  Created by Eric Wang on 4/22/15.
//  Copyright (c) 2015 Eric Wang. All rights reserved.
//

#import "CommentCell.h"

@implementation CommentCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        [self addAllSubviews];
    }
    return self;
}


-(void)addAllSubviews
{
    self.contentView.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1.0];
    
    
    self.bgView = [[UIView alloc]init];
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.bgView.layer setCornerRadius:5.0];
    [self.contentView addSubview:self.bgView];
    
//    @property(nonatomic,strong)UIImageView *headImageview;
    self.headImageview = [[UIImageView alloc]init];
    [self.headImageview.layer setCornerRadius:20.0];
    self.headImageview.layer.masksToBounds = YES;
    [self.bgView addSubview:self.headImageview];
//    @property(nonatomic,strong)UILabel *nameLabel;
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = [UIFont systemFontOfSize:17];
    [self.bgView addSubview:self.nameLabel];
//    @property(nonatomic,strong)UILabel *contentLabel;
    self.contentLabel = [[UILabel alloc]init];
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.textColor = [UIColor colorWithRed:80/255.0 green:80/255.0 blue:80/255.0 alpha:1.0];
    self.contentLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
    [self.bgView addSubview:self.contentLabel];
//    @property(nonatomic,strong)UILabel *floorLabel;
    
    self.floorLabel = [[UILabel alloc]init];
    self.floorLabel.textColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
    [self.bgView addSubview:self.floorLabel];
}

-(void)setCommentFrame:(CommentFrame *)commentFrame
{
    self.bgView.frame = commentFrame.bgView;
    
    
    _commentFrame = commentFrame;
    self.headImageview.frame= _commentFrame.headImageview;
    [self.headImageview sd_setImageWithURL:[NSURL URLWithString:_commentFrame.comment.user.icon] placeholderImage:[UIImage imageNamed:@"default_users_avatar.png"]];
    
    self.contentLabel.frame = _commentFrame.contentLabel;
    self.contentLabel.text = _commentFrame.comment.content;
    
    self.nameLabel.frame = _commentFrame.nameLabel;
    
    self.nameLabel.text = _commentFrame.comment.user.login;
    
    self.floorLabel.frame = _commentFrame.floorLabel;

    
}
-(void)setFloor:(NSIndexPath *)path
{
    self.floorLabel.text = [NSString stringWithFormat:@"%d楼",path.row];
}
@end
